<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=utf-8" errorPage="/error.jsp" isELIgnored="false" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles" prefix="tiles" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://www.opensymphony.com/oscache" prefix="cache" %>
<%@ taglib uri="http://atleap.blandware.com/taglib" prefix="atleap" %>
<html:xhtml />

<atleap:constants className="com.blandware.atleap.webapp.util.core.WebappConstants" var="CONTENT_LOCALES_COLLECTION_KEY" scope="page" />
<atleap:constants className="com.blandware.atleap.common.Constants" var="MIME_TYPE_PLAIN" />
<atleap:constants className="com.blandware.atleap.common.Constants" var="MIME_TYPE_HTML" />
<c:set var="filterBody" value="${requestScope.mailTemplate.plain}" />
<table cellpadding="0" cellspacing="0" border="0" class="tableView">
	<tr>
		<th><atleap:message key="core.mailTemplate.form.mimeType" /></th>
		<td>
			<c:choose>
				<c:when test="${requestScope.mailTemplate.plain}">
					<atleap:message key="core.mailTemplate.form.mimeType.plain" />
				</c:when>
				<c:otherwise>
					<atleap:message key="core.mailTemplate.form.mimeType.html" />
				</c:otherwise>
			</c:choose>
		</td>
	</tr>
	<tr>
		<th>
			<atleap:message key="core.mailTemplate.form.from" />
		</th>
		<td>
			<atleap:iterator items="${sessionScope[pageScope.CONTENT_LOCALES_COLLECTION_KEY]}" var="contentLocale">
				<div class="readOnlyField">
					<atleap:fieldValue valueMap="${contentLocale.title}" var="languageTitle" />
					<c:if test="${empty languageTitle}">
						<c:set var="languageTitle" value="${contentLocale.identifier}" />
					</c:if>
					${languageTitle}:&nbsp;<atleap:fieldValue valueMap="${requestScope.mailTemplate.from}" language="${contentLocale.identifier}" complexSearch="false" />
				</div>
			</atleap:iterator>
		</td>
	</tr>
	<tr>
		<th>
			<atleap:message key="core.mailTemplate.form.subject" />
		</th>
		<td>
			<atleap:iterator items="${sessionScope[pageScope.CONTENT_LOCALES_COLLECTION_KEY]}" var="contentLocale">
				<div class="readOnlyField">
					<atleap:fieldValue valueMap="${contentLocale.title}" var="languageTitle" />
					<c:if test="${empty languageTitle}">
						<c:set var="languageTitle" value="${contentLocale.identifier}" />
					</c:if>
					${languageTitle}:&nbsp;<atleap:fieldValue valueMap="${requestScope.mailTemplate.subject}" language="${contentLocale.identifier}" complexSearch="false" />
				</div>
			</atleap:iterator>
		</td>
	</tr>
	<tr>
		<th>
			<atleap:message key="core.mailTemplate.form.charset" />
		</th>
		<td>
			<atleap:iterator items="${sessionScope[pageScope.CONTENT_LOCALES_COLLECTION_KEY]}" var="contentLocale">
				<div class="readOnlyField">
					<atleap:fieldValue valueMap="${contentLocale.title}" var="languageTitle" />
					<c:if test="${empty languageTitle}">
						<c:set var="languageTitle" value="${contentLocale.identifier}" />
					</c:if>
					${languageTitle}:&nbsp;<atleap:fieldValue valueMap="${requestScope.mailTemplate.charset}" language="${contentLocale.identifier}" complexSearch="false" />
				</div>
			</atleap:iterator>
		</td>
	</tr>
	<c:if test="${!empty sessionScope[pageScope.MAIL_TEMPLATE_AVAIALABLE_VARIABLES_KEY]}">
		<tr>
			<td colspan="2" align="center">
				<br /><atleap:message key="core.mailTemplate.form.availableVariables" arg0="${sessionScope[pageScope.MAIL_TEMPLATE_AVAIALABLE_VARIABLES_KEY]}" />
			</td>
		</tr>
	</c:if>
	<tr>
		<td colspan="2" align="center">
			<atleap:message key="core.mailTemplate.form.body" />
		</td>
    </tr>
    <atleap:iterator items="${sessionScope[pageScope.CONTENT_LOCALES_COLLECTION_KEY]}" var="contentLocale">
        <tr>
		    <th>
				<div class="readOnlyField">
					<atleap:fieldValue valueMap="${contentLocale.title}" var="languageTitle" />
					<c:if test="${empty languageTitle}">
						<c:set var="languageTitle" value="${contentLocale.identifier}" />
					</c:if>
					${languageTitle}:
                </div>
            </th>
            <td>
                <c:set var="loadMethod" value="javascript" />
                <c:if test="${!requestScope.mailTemplate.plain}">
                    <c:set var="loadMethod" value="servlet" />
                </c:if>
                <atleap:iframe loadMethod="${loadMethod}">
                    <atleap:fieldValue valueMap="${requestScope.mailTemplate.body}" language="${contentLocale.identifier}" complexSearch="false" filter="${filterBody}" />
                </atleap:iframe>
    		</td>
    	</tr>
    </atleap:iterator>
</table>
<atleap:form action="core/mailTemplate/callUpdate" method="POST" validateOnSubmit="false">
    <html:hidden property="id" value="${requestScope.mailTemplate.id}" />
    <atleap:isUserInRole roles="core-mailTemplate-update">
        <atleap:submit styleClass="button"><atleap:message key="core.commons.buttons.callUpdate" /></atleap:submit>
    </atleap:isUserInRole>
    <atleap:cancel styleClass="button"><atleap:message key="core.commons.buttons.showList" /></atleap:cancel>
</atleap:form>
